<%@ Page Language="C#" Debug="true" ContentType="text/xml" Title="Reviewer.dk - RSS til nyheder" %>
<%@ Import Namespace="System.Xml" %>
<script language="C#" runat="server">

    void Page_load(Object sender, EventArgs e)
    {
        DateFromMySql NewDate = new DateFromMySql();
        string myconn = ConfigurationManager.ConnectionStrings["reviewer"].ConnectionString;
        string SQLstreng = "SELECT * FROM V2_Nyhed ORDER BY id DESC LIMIT 15";
        OdbcConnection dbconn = new OdbcConnection(myconn);
        OdbcCommand MyCommand = new OdbcCommand();

        dbconn.Open();
        
        MyCommand.Connection = dbconn;
        MyCommand.CommandType = CommandType.Text;
        MyCommand.CommandText = SQLstreng;
        
        OdbcDataReader MyReader = MyCommand.ExecuteReader();
        
        XmlTextWriter MyWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);

        MyWriter.WriteStartDocument();
        MyWriter.WriteStartElement("rss");
        MyWriter.WriteAttributeString("version", "2.0");
        MyWriter.WriteStartElement("channel");
        MyWriter.WriteElementString("title", "Reviewer.dk - Nyheder");
        MyWriter.WriteElementString("description", "Dansk side med daglige nyheder til spil, samt anmeldelser af spil til konsoller og pc");
        MyWriter.WriteElementString("link", "http://www.reviewer.dk");
        MyWriter.WriteElementString("ttl", "60");
        MyWriter.WriteElementString("language", "da");
        MyWriter.WriteElementString("copyright", "Copyright 2008 Reviewer.dk");
        MyWriter.WriteElementString("lastBuildDate", DateTime.Now.ToString());
        MyWriter.WriteStartElement("image");
        MyWriter.WriteElementString("url", "http://www.reviewer.dk/grafik/rsslogo.jpg");
        MyWriter.WriteElementString("link", "http://www.reviewer.dk");
        MyWriter.WriteElementString("title", "Reviewer.dk - Nyheder");
        MyWriter.WriteElementString("width", "100");
        MyWriter.WriteElementString("height", "52");
        MyWriter.WriteEndElement();
        while (MyReader.Read())
        {
            MyWriter.WriteStartElement("item");
            MyWriter.WriteElementString("title", MyReader["Titel"].ToString());
            MyWriter.WriteElementString("category", MyReader["Emne"].ToString());
            MyWriter.WriteElementString("pubDate", BuildPubDate((DateTime)MyReader["Dato"]));
            MyWriter.WriteElementString("description", MyReader["Header"].ToString());
            MyWriter.WriteElementString("link", "http://www.reviewer.dk/" + UI.LinkMake.LinkNews(MyReader["Id"].ToString(), MyReader["Titel"].ToString()));
            MyWriter.WriteEndElement();
        }
        dbconn.Close();
        MyWriter.WriteEndElement();
        MyWriter.WriteEndElement();
        MyWriter.WriteEndDocument();
        MyWriter.Flush();
        MyWriter.Close();
    }
    private string BuildPubDate(DateTime d)
    {
        try
        {
            string RV = "";
            string day = d.Day.ToString();
            if (day.Length == 1) { day = "0" + day; }
            string month = d.Month.ToString();
            if (month == "1") { month = "January"; }
            else if (month == "2") { month = "February"; }
            else if (month == "3") { month = "March"; }
            else if (month == "4") { month = "April"; }
            else if (month == "5") { month = "May"; }
            else if (month == "6") { month = "June"; }
            else if (month == "7") { month = "July"; }
            else if (month == "8") { month = "August"; }
            else if (month == "9") { month = "September"; }
            else if (month == "10") { month = "October"; }
            else if (month == "11") { month = "November"; }
            else if (month == "12") { month = "December"; }

            string mTime = "";
            DateTime mDate = d.ToUniversalTime();
            if (mDate.Hour.ToString().Length == 1)
            {
                mTime = "0" + mDate.Hour.ToString();
            }
            else
            {
                mTime = mDate.Hour.ToString();
            }

            mTime += ":";
            if (mDate.Minute.ToString().Length == 1)
            {
                mTime += "0" + mDate.Minute.ToString();
            }
            else
            {
                mTime += mDate.Minute.ToString();
            }

            mTime += ":";
            if (mDate.Second.ToString().Length == 1)
            {
                mTime += "0" + mDate.Second.ToString();
            }
            else
            {
                mTime += mDate.Second.ToString();
            }

            RV = d.DayOfWeek.ToString().Substring(0, 3);
            RV += ", " + day + " " + month.Substring(0, 3);
            RV += " " + d.Year.ToString() + " " + mTime + " GMT";
            return RV;

        }
        catch (Exception)
        {
            return null;
        }
    }
    
</script>